home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earkit / mail / thor / thor25_arexx.lha / MailtoScripts / SendMail.thor < prev   
Text File  |  1996-01-03  |  5KB  |  164 lines

  1. /* SendMail.thor by Troels Walsted Hansen <troels@stud.cs.uit.no>
  2. ** $VER: SendMail.thor v1.10 (27.12.95)
  3. **
  4. ** This is a very simple script designed for use with AMosaic's new mailto:
  5. ** support.  Set ENV:Editor to your prefered editor (I use "GED Y"), and
  6. ** ENV:SendMail to "RX THOR:Rexx/SendMail.thor" (substitute "THOR:Rexx/" for
  7. ** the path where you put this script).
  8. **
  9. ** Now change the two variables below to whatever fits for your setup.
  10. ** MailSystem is the name of your TCP/SOUP/UUCP/whatever email system in
  11. ** THOR, and MailConfName is obviously the name of your email conference in
  12. ** THOR.
  13. **
  14. ** Setting AddSignature to 'Yes' will make SendMail.thor read your conference/
  15. ** BBS/global signature settings and add that signature to your mails.
  16. **
  17. ** Sending a mailto: with AMosaic should now produce an EnterMsg event in THOR.
  18. ** The mail will be sent the next time you use Send Events from ConnectTHOR,
  19. ** upload your SOUP reply package, or whatever.
  20. **
  21. ** Note: THOR does not have to be running for this script to work!
  22. **
  23. ** History:
  24. ** ¯¯¯¯¯¯¯¯
  25. ** SendMail.thor v1.00 (07.08.95)
  26. **  · First release.
  27. **
  28. ** SendMail.thor v1.10 (27.12.95)
  29. **  · Now optionally appends signature configured in THOR to the email.
  30. **  · Updated my email address :-)
  31. **  · Implemented previously non-existant errorchecking and reporting
  32. */
  33.  
  34. MailSystem = 'News&Mail'
  35. MailConfName = 'EMail'
  36. AddSignature = 'Yes'
  37.  
  38. /* DON'T CHANGE ANYTHING BELOW HERE */
  39.  
  40. if ~show('p', 'BBSREAD') then do
  41.     address command
  42.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  43.         "WaitForPort BBSREAD"
  44. end
  45.  
  46. address(BBSREAD)
  47.  
  48. /* parse the header AMosaic provides */
  49.  
  50. str = readln('STDIN')
  51.  
  52. if(upper(word(str, 1)) ~= "TO:") then
  53. do
  54.     call showerror("First headerline wasn't a To:, please don't mess with the header AMosaic provides.")
  55.     exit 20
  56. end
  57. else EVENT.TOADDR = word(str, 2)
  58.  
  59. str = readln('STDIN')
  60.  
  61. if(upper(word(str, 1)) ~= "SUBJECT:") then
  62. do
  63.     call showerror("Second headerline wasn't a Subject:, please don't mess with the header AMosaic provides.")
  64.     exit 20
  65. end
  66. else EVENT.SUBJECT = substr(str, 10)
  67.  
  68. /* skip X-Mailer: line */
  69.  
  70. call readln('STDIN')
  71.  
  72. /* put the body of the message in a file with a unique name */
  73.  
  74. UNIQUEMSGFILE bbsname '"'MailSystem'"' stem UNIQUEFILE
  75. if(rc ~= 0) then
  76. do
  77.     call showerror('UNIQUEMSGFILE BBSRead command failed: ' || BBSREAD.LASTERROR)
  78.     exit 20
  79. end
  80.  
  81. call open(tmp, UNIQUEFILE.NAME, W)
  82.  
  83. do until eof('STDIN')
  84.     call writeln(tmp, readln('STDIN'))
  85. end
  86.  
  87. /* add signature from the EMail conference/BBS/Global Settings */
  88.  
  89. if(upper(AddSignature) = 'YES') then
  90. do
  91.     GETCONFDATA BBSNAME '"'MailSystem'"' CONFNAME '"'MailConfName'"' STEM CONFD
  92.     if(CONFD.SIGNATURE = "") then
  93.     do
  94.         GETBBSDATA BBSNAME '"'MailSystem'"' STEM BBSD
  95.         if(BBSD.SIGNATURE = "") then
  96.         do
  97.             GETGLOBALDATA STEM GLOBD
  98.             if(GLOBD.SIGNATURE = "") then
  99.             do
  100.                 call showerror('No signature configured in either conference, bbs og global settings! Please correct this in THOR or turn off signature adding in SendMail.thor.')
  101.                 exit 20
  102.             end
  103.             else sig = GLOBD.SIGNATURE
  104.         end
  105.         else sig = BBSD.SIGNATURE
  106.     end
  107.     else sig = CONFD.SIGNATURE
  108.  
  109.     drop CONFD.; drop BBSD.; drop GLOBD.
  110.  
  111.     if(sig ~= "") then
  112.     do
  113.         /* signature may be a filename */
  114.  
  115.         if(exists(sig)) then
  116.         do
  117.             call open(sigfh, sig, R)
  118.  
  119.             do until eof(sigfh)
  120.                 call writeln(tmp, readln(sigfh))
  121.             end
  122.  
  123.             call close(sigfh)
  124.         end
  125.         else call writeln(tmp, sig) /* or just a string */
  126.     end
  127. end
  128.  
  129. call close(tmp)
  130.  
  131. /* fill out some more variables that BBSREAD require */
  132.  
  133. EVENT.CONFERENCE = MailConfName
  134. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  135.  
  136. /* write the event */
  137.  
  138. WRITEBREVENT bbsname '"'MailSystem'"' event 0 stem EVENT
  139. if(rc ~= 0) then
  140. do
  141.     call showerror('WRITEBREVENT BBSRead command failed: ' || BBSREAD.LASTERROR)
  142.     exit 20
  143. end
  144.  
  145. exit 0
  146.  
  147. /* sophisticated errorhandling :-) */
  148.  
  149. showerror: procedure expose MailSystem MailConfName AddSignature
  150.     parse arg errormsg
  151.  
  152.     p=show('P',,)
  153.     if(pos('AMOSAIC.', p) > 0) then amosaicport = word(substr(p, pos('AMOSAIC.', p)), 1)
  154.     else return
  155.  
  156.     call open(err, "T:SendMail.thor.error.html", W)
  157.     call writeln(err, "<HTML><HEAD><TITLE>SendMail.thor encountered an error</TITLE></HEAD><BODY><H1>Sending mail aborted</H1>" || errormsg || "<P>Please remember to verify the following settings:<PRE>MailSystem = '" || MailSystem || "'" || '0a'x || "MailConfName = '" || MailConfName || "'" || '0a'x || "AddSignature = '" || AddSignature || "'" || "</PRE>If they are wrong, edit SendMail.thor and correct them. <hr> If this should happen to be an erroneous error, don't hesitate to contact the author, <A HREF=" || '"' || "http://www.cs.uit.no/~troels" || '"' || ">Troels Walsted Hansen</A>, preferably by <A HREF=" || '"' || "mailto:troels@stud.cs.uit.no" || '"' || ">email</A>.")
  158.     call close(err)
  159.  
  160.     address(amosaicport)
  161.     'JUMP URL file://localhost/T:SendMail.thor.error.html'
  162.  
  163.     return
  164.